package com.maximporges.riatest;

public class IntegrationFactory
{
   @SuppressWarnings("unchecked")
   public Integration newIntegration(Configuration configuration) throws Exception
   {
      Integration instance;
      String integrationClassName = configuration.getIntegrationClassName();
      
      try
      {
         Class clazz = Class.forName(integrationClassName);
         instance = (Integration) clazz.getConstructor().newInstance();
         instance.setConfiguration(configuration);
      }
      catch (ClassCastException e)
      {
         throw new ClassCastException("The specified classname " + integrationClassName + " is not an instance of Integration.");
      }

      return instance;
   }
}
